﻿<div bsModal #createOrEditModal="bs-modal" (onShown)="onShown()" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="createOrEditModal"
     aria-hidden="true" [config]="{backdrop: 'static'}">
    <div class="modal-dialog">

        <div class="modal-content">

            <form *ngIf="active" #roleForm="ngForm" novalidate (ngSubmit)="save()">

                <div class="modal-header">
                    <button type="button" class="close" (click)="close()" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title">
                        <span *ngIf="edition.id">{{l("EditEdition")}}: {{edition.displayName}}</span>
                        <span *ngIf="!edition.id">{{l("CreateNewEdition")}}</span>
                    </h4>
                </div>

                <div class="modal-body">
                    <tabset class="tab-container tabbable-line">
                        <tab heading="{{l('EditionProperties')}}">
                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input #editionNameInput class="form-control" type="text" name="EditionDisplayName" [ngClass]="{'edited':edition.displayName}" [(ngModel)]="edition.displayName" required maxlength="64">
                                <label>{{l("EditionName")}}</label>
                            </div>

                            <label>{{l("SubscriptionPrice")}}</label>
                            <div class="md-radio-inline">
                                <div class="md-radio">
                                    <input id="EditEdition_IsFree" name="SubscriptionPrice" class="md-radiobtn" [(ngModel)]="isFree" (ngModelChange)="resetPrices($event)" [value]="true" type="radio">
                                    <label for="EditEdition_IsFree">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        {{l("Free")}}
                                    </label>
                                </div>
                                <div class="md-radio">
                                    <input id="EditEdition_IsPaid" name="SubscriptionPrice" class="md-radiobtn" [(ngModel)]="isFree" [value]="false" type="radio">
                                    <label for="EditEdition_IsPaid">
                                        <span class="inc"></span>
                                        <span class="check"></span>
                                        <span class="box"></span>
                                        {{l("Paid")}}
                                    </label>
                                </div>
                            </div>

                            <div class="row" *ngIf="!isFree">
                                <div class="col-md-6">
                                    <div class="form-group form-md-line-input form-md-floating-label">
                                        <input type="text"
                                               name="MonthlyPrice"
                                               currencyInput
                                               class="form-control"
                                               autocomplete="off"
                                               [ngClass]="{'edited':edition.monthlyPrice}"
                                               [required]="!isFree"
                                               [(ngModel)]="edition.monthlyPrice" />

                                        <label>{{l("MonthlyPrice")}}</label>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group form-md-line-input form-md-floating-label">
                                        <input type="text"
                                               name="AnnualPrice"
                                               currencyInput
                                               class="form-control"
                                               autocomplete="off"
                                               [ngClass]="{'edited':edition.annualPrice}"
                                               [required]="!isFree"
                                               [(ngModel)]="edition.annualPrice" /> 
                                         
                                        <label>{{l("AnnualPrice")}}</label>
                                    </div>
                                </div>
                            </div>

                            <div [hidden]="isFree" class="paid-features">

                                <div class="md-checkbox-list">
                                    <div class="md-checkbox">
                                        <input id="EditEdition_IsTrialActive" class="md-check" type="checkbox" name="isTrialActive" [(ngModel)]="isTrialActive" />
                                        <label for="EditEdition_IsTrialActive">
                                            <span class="inc"></span>
                                            <span class="check"></span>
                                            <span class="box"></span>
                                            {{l("IsTrialActive")}}
                                        </label>
                                    </div>
                                </div>

                                <div class="form-group form-md-line-input form-md-floating-label" *ngIf="isTrialActive">
                                    <input class="form-control"
                                           type="number" name="TrialDayCount"
                                           [required]="isTrialActive"
                                           [(ngModel)]="edition.trialDayCount"
                                           [ngClass]="{'edited':edition.trialDayCount}">
                                    <label>{{l("TrialDayCount")}}</label>
                                </div>

                                <div class="md-checkbox-list">
                                    <div class="md-checkbox">
                                        <input id="EditEdition_IsWaitingDayActive" class="md-check" type="checkbox" name="IsWaitingDayActive" [(ngModel)]="isWaitingDayActive" />
                                        <label for="EditEdition_IsWaitingDayActive">
                                            <span class="inc"></span>
                                            <span class="check"></span>
                                            <span class="box"></span>
                                            {{l("WaitAfterSubscriptionExpireDate")}}
                                        </label>
                                    </div>
                                </div>

                                <div class="form-group form-md-line-input form-md-floating-label" *ngIf="isWaitingDayActive">
                                    <input class="form-control"
                                           type="number" name="WaitingDayAfterExpire"
                                           [required]="isWaitingDayActive"
                                           [(ngModel)]="edition.waitingDayAfterExpire"
                                           [ngClass]="{'edited':edition.waitingDayAfterExpire}">
                                    <label>{{l("WaitingDayAfterExpire")}}</label>
                                </div>

                                <label>{{l("WhatWillDoneAfterSubscriptionExpiry")}}</label>
                                <div class="md-radio-inline">
                                    <div class="md-radio">
                                        <input id="EditEdition_ExpireAction_DeactiveUser" name="ExpireAction" class="md-radiobtn" [(ngModel)]="expireAction" [value]="expireActionEnum.DeactiveTenant" (ngModelChange)="removeExpiringEdition($event)" type="radio">
                                        <label for="EditEdition_ExpireAction_DeactiveUser">
                                            <span class="inc"></span>
                                            <span class="check"></span>
                                            <span class="box"></span>
                                            {{l("DeactiveTenant")}}
                                        </label>
                                    </div>
                                    <div class="md-radio">
                                        <input id="EditEdition_ExpireAction_AssignEdition" name="ExpireAction" class="md-radiobtn" [(ngModel)]="expireAction" [value]="expireActionEnum.AssignToAnotherEdition" type="radio">
                                        <label for="EditEdition_ExpireAction_AssignEdition">
                                            <span class="inc"></span>
                                            <span class="check"></span>
                                            <span class="box"></span>
                                            {{l("AssignToAnotherEdition")}}
                                        </label>
                                    </div>
                                </div>

                                <div class="form-group form-md-line-input form-md-floating-label edition-list" *ngIf="expireAction == expireActionEnum.AssignToAnotherEdition">
                                    <select name="expiringEdition" class="form-control edited" [(ngModel)]="edition.expiringEditionId" [minValue]="expireAction == expireActionEnum.AssignToAnotherEdition ? 1:0" [ngClass]="{'edited':edition.expiringEditionId}">
                                        <option *ngFor="let expiringEdition of expiringEditions" [value]="expiringEdition.value">{{expiringEdition.displayText}}</option>
                                    </select>
                                </div>
                            </div>
                        </tab>
                        <tab heading="{{l('Features')}}">
                            <feature-tree #featureTree></feature-tree>
                        </tab>
                    </tabset>
                </div>

                <div class="modal-footer">
                    <button [disabled]="saving" type="button" class="btn btn-default" (click)="close()">{{l("Cancel")}}</button>
                    <button type="submit" class="btn btn-primary blue" [disabled]="!roleForm.form.valid" [buttonBusy]="saving" [busyText]="l('SavingWithThreeDot')"><i class="fa fa-save"></i> <span>{{l("Save")}}</span></button>
                </div>

            </form>

        </div>
    </div>
</div>